package com.pfsbuilder;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.tree.TreeCellRenderer;

/**
 * <p>
 * Title: PFS
 * </p>
 * 
 * <p>
 * Description:
 * </p>
 * 
 * <p>
 * Copyright: Copyright (c) 2005
 * </p>
 * 
 * <p>
 * Company: Petersoft
 * </p>
 * 
 * @author Peter
 * @version 2005
 */
public class PFSDefaultTreeCellRenderer extends JLabel implements TreeCellRenderer {
	static ImageIcon fileIcon = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/tree/file/file.png"));
	static ImageIcon dirOpenIcon = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/tree/dir/dirOpen.png"));
	static ImageIcon dirCloseIcon = new ImageIcon(com.pfsbuilder.PFSBuilder.class.getResource("images/tree/dir/dirClose.png"));
	BorderLayout borderLayout1 = new BorderLayout();

	public PFSDefaultTreeCellRenderer() {
		super();
		try {
			jbInit();
		} catch (Exception ex) {
			ex.printStackTrace();
			if (com.pfsbuilder.Global.GUI) {
				new PExceptionDialog(ex, com.pfsbuilder.Global.sessionNumber).setVisible(true);
			}
		}
	}

	public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
		if (value.getClass() == File.class) {
			File node = (File) value;
			String text = node.getName();
			this.setText(text);

			if (node.isFile()) {
				this.setIcon(fileIcon);
			} else {
				if (expanded) {
					this.setIcon(dirOpenIcon);
				} else {
					this.setIcon(dirCloseIcon);
				}
			}

			if (tree.isEnabled()) {
				if (sel) {
					this.setBackground(new Color(180, 226, 252));
				} else {
					this.setBackground(tree.getBackground());
				}
			} else {
				this.setBackground(tree.getBackground());
			}
			return this;
		} else {
			return new JLabel();
		}
	}

	private void jbInit() throws Exception {
		this.setOpaque(true);
	}
}
